a particularly anal PEP8 go through, and some little tweaks

@andrewphilipsmith I've gone through this in vim with pylint and pyflakes on, and kept resolving things until the little quickfix window vanishes (that's my litmus test). Also simplified a couple of bits (removed reduce in favour of using string.join), and added some notes (there's a possible vulnerability in the aggregator, though I guess it probably doesn't "matter" since it's in-memory, but may cause errors anyway).

Haven't tested this yet, so this was a pure code-reading exercise!

(Sorry - recreated as I didn't want to PR into master)
`l_dict` - I couldn't make out what the `l_` was for (maybe lookup?) -- again, generally I think it is better to just name variables for what they do rather than what they are. You can always use `assert` for type checking. I called it query args, but that might not be the best name either *shrug*