Some edits and started sketching the types for the state machine.