added group by M.gid to remove duplicate mod entries in query