Added missing error check.
Added more error logging.