Ahh.. sorry, I didn't notice the code was already there. In that case this pull request is fine. In general I think setting variables should probably be simplified, and shouldn't require double loop.