refactor a bit and simplify flow running