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

Refactor db layer