Implement without use of mutable stack

IMHO the algorithm is simpler in this form also