add new functions and fix bugs