Make error handling a bit more robust