Added comments to several lines for better understanding.