refactored Engine and startup code so Engine can be derived from and carry the state that was previously stored in global variables.