Use each_with_index and redo to do the same thing without a while loop and position counter.