solution for final exercises 2