fixing bug with incorrect var ref