fixed if cleanup entity check