Implemented a basic state machine