Use pop over shift to avoid reverse

Because Array#reverse is O(N)

@arthurnn @Thibaut @dylanahsmith