Reworked to put less demand on the stack.