more minor bug fixes
used stack to replace a bunch of tracking variables
stack bugs