fix the order in which array elements are removed

start from the end otherwise you get a wonderful index out of bounds
exception