Major optimizations

Up to twice as fast in many scenarios.