made changes that hopefully fix the segfault problem