More improvements to error handling, mostly when reading from buffers