fixing bug with removing variables