core:Refactoring the code related to the states. The code moved to the StateManagement class.