Added better error logging.