fixed "infinite loop"