Index extraction code with tests