array.pop mutates the length of the array. The while loop needs to inspect this instead of incrementer