fixing inifinite loop