Split up iteration and push error handling into a method