Cleaning the comments and restructuring the functions.  Various suggestions made