wrote the functions for assignment 2