added extensive error logging to log