Refactoring the core: moving code related to state managment to the class StateManagment