added function recursion exception code from Paul Torsten