Fixed db initialization so that it is more sane, and also accessible by separate scripts