Using a stack for recursive routines