These kind of ifs have been repeated times and again, what about a generic helper function? In general I see a lot of duplication in the dispatch functions