Added comments into code for better clarity