feat(engine): modularize the engine and add tests