fix minor bug that stop the loop before the end