Replaced a wrong "if" by a "while".