Bug fix: potential slice bounds out of range