Improving error handling a bit