Proper recursion limiter, and code cleanup