Commented the code for more readability