Reformatted and improved doc strings. Also some code cleanup.