refactoring the engine