changed the switch between states statement