fixed up some bugs, moved things off stack allocation (not sure if we'll have enough space on the sstack