refactored db_setup