Refactored engine and added new engine tests.