loop count fix