Factored out index logic into separate module