implemented question 4 (hw5)