Fix (global) db leakage, by making db local.

Thanks to mickhansen for the fix.