Major work on the database.

Clients are added to the database if they do not exist.