fix sorting of tuples/lists in the iterate helper, and guard against sorting errors raising exceptions
add some iterate helper tests