Check for object instance before cast