change ".all.uniq" to ".uniq_by(&:court_id)"