Split Factor in modules: Factor, BayesNetwork and Main.