Cleaned up the recursion code.