undefinedFix function and some bugs fix