fixed algorithm error (ArrayIndexOutOfBound)