Fix segfault problem