Improved logging and added some more docstrings.