Improve doc blocks and minor bug fixing.