Update the logic with comments

Added comments to both functions