Merge pull request #224 from mzry1992/refactor-db-layer

Refactor db layer