Added comments to the code to make it more understandable.