refactor the engine slightly with some improvements in mind