Factored out common code.

Also renamed to use hyphens instead of underscores.
Improved writable cdb interface.

Updated tests to match.
Improved readable cdb interface.

Updated tests to match.