implemented the functions required in the assignment