Add docstrings and update as per comments