Changed if statemnt to until block