working right in some condition, fix segment fault.