hw2 function done !