I find this loop (and the related dictionaries above it) a quite confusing.  Is there anyway to "unroll" this to make it more clear exactly what it's setting up (even if it ends up being more lines of code)?