Closure used to fix iteration problems