can't this be moved outside the while ?