Add some documentation and minor code changes