Wrote the functions for assignment 2