only compile indexing function once