fix segfault problems