refactor to only use a single db connection instead of a butt-load of them