improved db handling