Remove recursion from dong/ri indexer function