modify some function and add comments