Clean up logging code and flesh out the tests.