Database functions refactoring.