breaking recursion gracefully