added docstrings and updated code