move dispatch function into script