fix stack bug and update tests accordingly