Stack fixes

Improved stack branch, fixed some errors but still needs improvement.