changed if statement to until