Handle undefined errors more elegantly.