var w,h: changed from global to local scope