handle end of each loop more gracefully