Append head transactions without stack overflow

Implemented with a while loop. Cannot be implemented as tail recursive because of the catch statement.