Commented the code for easier understanding