smart make some changes for original function

do some changes to make code more Robustness