Database call refactoring