The chunk of code in the inner for loop could be refactored into its own function. The parent function is already a bit long. [optional]