Added new state and refactored a lot.