Updated code to use newInvalidRefError