Indexing algorithm implemented and works fine!