Raise API errors as exceptions
API refactoring, improved docstrings