modified the functions as required by the assignment