Refactored to add in StateManager