refactoring engine structure