Debug logging and error catching.