implemented question 5 (hw5)