Finished basic state machine