Wrote some comments so that the code is better to understand for noobs like myself