Performance improvements

several hotspot optimizations for memory + cpu consumption
I think this and the following line cause the test failures. At least some of them.