Refactor engine, use Optionals in the state manager.