Added more error condition checks.