simplify the looping structure