refactored sem stack to use trees