fixed extra iteration bug