exercise 31 with database (incomplete)