Changed previous position to stack (implemented via array) instead of single value to allow for multiple levels of return positions.