cleaned up, added docstrings, compressed function calls.