Fixed segfault issues