Would it make sense to try and build up various aspects of the data variable then just merge once at the end? 

I could probably do that myself at the end, but... :)