New implementation of exercise 2