db config and some refactoring