fix some bugs and add some function