Solution for the exercise