fix bug caused by undefined variables due to their missuse