Fix a bug: slice bounds out of range