Fixed some bugs with the engine