Did some renaming and fixed while loop to just increment the index