refactored engine