fixed issue with var scope