optimization to indices() method