Refactored ActiveRecord `first` method to get rid of duplication.