Add tests for Reference::equals and fix found bug