add function, bug fix