It would help to know the error you're getting, but from looking at what code you have here, it seems that maybe it's a recursion problem.
You must be careful with recursion and make sure that your flow is correct. ie every time execution "jumps" and continues in a different instance...