Refactored state to context