Abstracted the db factories a bit to make things cleaner