Refactored database relationship