Bug fix

Correction : while loop instead of if loop