Fixed  recursive bug with getRelatedCount()