try to make error handling more robust