I think this loop could be written in a way that it won't require iterating over the fields and the vals separately. I can't work on an example right now, I'm sorry.