rework of the primary engine, added some tests and made them pass