State Machines

Read - no comments needed I think

(click for code)