move queries from controller into query builder