extract index logic into method

Before this was repeating the same logic over and over to get the index of an entry (if one exists).
This just extracts that similar logic into it's own method.