Minor engine code cleanup

Made some things a little tidier, and fixed a few variables.