fix segment fault bug