Fully working code for question 4