how to update variable in function