Finished version of the exercise.