Code refactoring in engine