private static bool AddBetterActiveNode(HashSet <ActiveNode> breakPointNodes, ActiveNode newNode) { var competitor = breakPointNodes.FirstOrDefault(x => x.FitnessClass == newNode.FitnessClass); if (competitor == null) { breakPointNodes.Add(newNode); return(true); } else if (newNode.IsBetterThan(competitor)) { breakPointNodes.Remove(competitor); breakPointNodes.Add(newNode); return(true); } else { return(false); } }