database interface mostly done