wrote the 2 functions to complete assignment