fixing var scope