Small engine bugfixing/refactoring

Change-Id: Iba8c237dc93cf63ad4877b321851fa52c735163b