Updated solution for exercise 2