refactor dispatcher code some to clean it up.