Fixed bug with state transition