working version of generic indexing