Fixed bug causing segfault