Fixed numerous bugs in relatedTo inferencing