Added additional error handling.