Performance improvements

several hotspot optimizations for memory + cpu consumption