added explanatory comments in the code.