refactoring database calls