added my code to implement the two functions per the assignment