Fix segmentation fault when running tests