Use groupBy instead of contains