better error handling when reference is not found