indexing: making sure that indexing works for IMP and IMP++
indexing: refactoring the code to make it cleaner