What a mess! Rewrote a query, with proper indentation, to replace vars and mutate values to properties with the variables defined at the end. Still slightly silly, but more comprehensible.
… I must use this list comprehension stuff more.