BUG-1493: split off recursion tracking and rework it