added n_threadvariables to each functions