Refactored state update