added docstrings and comments, cleaned up old code