Refactors some of the indexOf code.