breakup query module into easier to read pieces