new functions and remove bugs

new functions and remove bugs