changed logging to better detect errors
changed logging to better detect errors
more commenting and formatting