fixed var scope bug --KW