Added docstrings, minor cosmetic reformatting.