removed global variable in timeout function