Mod: factored common mysql code