completed functions and function generator