move all computations to stack for output

Nearly working correctly. Last two data items are off-by-one in the stack