Refactor Bayesian Networks codebase