untangle nested comprehension by using intermediate vars

This seemed like the only ugly part in the entire codebase.