Add null pointer check, fix segment fault 11 bug.
waiting for futrher test