Fix wrong iteration direction