Refactored the state handling
Merge