fixing bug with random references