Added a working function to question 1