Use StateT to manage EngineState

This is the pull request for the "Use StateT to manage EngineState" commit