Refactors StateManager into seperate file