Added comments to the program to understand it better