Factors out dispatch-fn.