Fsm

Clean enough to merge back to master.