added while loop to count down array length and POP array elements to new array