Cleaned up the public API, added inline docs.