Add documentation and minor code-refactoring

I always prefer API to api.