Fixed a bug in reference checking.