How To Prevent Stack Overflow In Recursion