Master State Machines

Finished coding master state machines, needs some debugging and compiling before being merged. Stay tuned...