More work on db structure and db related code