Added a working function for question 2