added group by for expired_and_still_pending scope