Minor refactoring.
Add unit test for dout.