Added docstrings and made some changes for better pythonic style.