State machine *almost* working perfectly!