refactored some portions of the engine