Refactor flow

Some improvements to flow, as suggested by @mel-quark