Error logging

Added better error logging.