More intelligent error handling