State Machine

restructure states to use a machine
State Machine working