Completed Setting Up The State Machine