factorial function works but causes a stack overflow