added better error trapping/logging