split into 2 while loops