Added Key-Value API.

Lots of changes go along with this one:

* Specs for the API;
* Bug fixes; and
* Lots and lots of utility functions.