refactor action_dispatch to use flat_map