Miscellaneous improvements in FactorGraph, Permute, HAK