Added flush commands when switching states