fixed bug that the last line is iterated twice