Fixed segfault bug but introduced another one :(