Tighten unit test
Use a more general interface with WriteCommand

This is to ease testing.
Add unit test for command package