Beef up error handling to avoid issues like #57