recursion - early exit, performance improvements