polish API, add tests and docs