Commenting has been enhanced and the code has been refined