added better error handling/logging