Using stacking where necessary

Instead of stacking beforehand, we operate on the original input and
stack when necessary.