Refactor server and factors into db package.