implements the functions for assignment 2