split out db code, new setup routine