Improve documentation and comments, add API reference