Improving checks for valid objects before using