Improved database detection.