Add tests and refactor how post functions use db variable.