refactored to use array.shift()