Refactored database code to remove duplication in handling of 'provides'.