Remove buggy while loop