Refactored Engine and added new tests.