Added additional error handling