Could you split this block and the parts above into their own function as well? Just to make it a little clearer who's doing what.