Split out indexing code