add some new functions and fix bugs