Fixed bug in reference check.