Refactoring the duplicate code in the engines