Optimized database helper code