Added optional entity type detection by using relatedType