Fixing @maxjusticz 's db code