Minor error checking and docstrings added.