refactor dispatch method into its own function