Refactor the Mode into a trait, add FlowState

Addresses #462