fixed a loop optimation bug