better with a ref validity check