new functions and fix bugs