Four levels of indentation and then lots of `\` linebreaks is not super-nice.
Would extracting the two inner loops into a utility function help?