solution for final exercise 12