Fix bug, if length == 1 it will crash due to out of range