Introduced states, state transitions and cleaned up a lot