Modified last function for question 2.4