Some fixes and polish to the engine