Adding solution for exercise 8.