Improved db functionality