CHANGED: reffactored indexing functionality