Reworked to put less demand on the stack.
Merge pull request #2 from jaspervdg/master

Reworked to put less demand on the stack.