Hopefully fixed some segfault issues