fixed random segfault bug