Complete initial implementation.  Still needs tests.