Improve documentation and update inline comments