Refactor dataflow