fixed some code style and removed resetting the startingIndex.