Javascript state machine that keeps things simple