Commenting has been enhanced and the code has been refinedand bugs are fixed