Fixed bug causing a segfault