Add jsdocs to the public api and fix error stacks