fixing state machines (not quite done)
-rewrote all the state logic
-added commands to try and make this logic simpler
included the js files from last commit