bug fix in Function