fixing ref bugs