changed codes in function "val_num"