Refactored db routines into separate class/module.