Added trace code to write verbose output when errors occur