fix segfault caused by string manipulation bug.