Improved database handling