Added comments to both functions and also gave an overview of the entire code.