added better error handling support