Document improvements and minor code fixes