fixing setTimeout bug