Fixed calls from outside

While loop should be out of the if block