Fixed never-ending loops