implementation ofAssignment 2 functions