new functions and bug fix