Refactor ElementsIndexer.getNextElement to not use recursion

Problem
===
Exceeded maximum call stack in `ElementsIndexer.getNextElement`

Solution
===
Since we are simply iterating over an array, we can save memory by storing and incrementing the current array index, using a traditional `for` loop.