Use defaultdict where useful.
Add custom url_for function.
Remove newline.
Fix coding style.