Complete rewrite of engine.