updated the getRelationship Function to make it more efficient