added thorough comments to the refactored file