fixed loop count defect