Added code for switching states based on strings and custom conditions from each state