patched some segfault issues