Added docstrings and explanations.