just query refactor from ugly SQL to almost-as-ugly Sequel