Basic state machine. Needs Debugging, but wanted it on git