refactoring out a method to incremement the index