Added comments to explain each part of the code.