Improving some error handling.