fix bugs and add some function