database operations refactoring