Fixed bug with checking for setting ref