factored out db stuff