Moved dispatch function from main module to dispatch module.