Trying to improve error handling a bit.