Added more error handling.