State machine improvements