Rewrote and optimized almost all engine.