Refactor flow_network