Added comments to document the code better