adjusted some funcs and fixed several bugs of the merge from r96