rewrite of database

New version with a rewrite of the database based on Jose's comments