redid the statemachine, now has numbered states and separate state handler, did some cleanup