a fix to segfault error and inference