Refactoring: using AR instead of raw SQL.