fixing some string manipulation problems that might cause a segfault