replacing manual index with ruby method