some refactoring on dbi.