reworked db, first part of the changes for requested features.