Improve database ensure

Solving Issue #9

I've tested but more test would be great.