fix bugs & add some functions