A few error-handling fixes