moved to before the while loops