Refactoring FactorGraph