Added a docstring, a comment and improved logging