add DB handling

and some style fixes
Merge pull request #5 from zard17/master

add DB handling