added func and bug fixes