Moved allocations around
Attempted fix at mem leak