final solution

the functions have been defined