Improved error handling a bit.