Refactor: Replace use of the heap with the stack