Made the error handling a bit more elegant, causing fewer failures.