refactoring more db stuf - moving functionality into methods