setting up database service, misc. restructuring and cleanup