Issue 294 (ValueError in response to invalid reference)

Fix and tests for #294.