some mistakes in loop