NFSM: Non-Deterministic Finite State Machine, modified from fsm.py created by Noah Spurrier 20020822