Reorg and simiplification of app. Fixed error when creating new db.