Modularizing db functions