changed global varible to local