Make sure that both loops terminate