Separated environment side effects from iterating function