Refactor of the engine class and added some unit tests