refactor engine