Clean up a few little pieces of code with defaultdicts.