added some comments in code for more readability