Lots of style cleanup.

Also moved the date formatting to utils.py, and added unit tests for it.