add functions, correct some bugs & faults