A number of basic cleanups and some changes from discussing
the API with lvh.