Setting Up The State Machine