refactor sem 4
more minor performance improvements