Moved few functions around. Added beginnings of being able to use db in place of inmem