Fixed some problems in the code and refactored it to make it more Pythonic. Marginalize makes a call to FactorMarginalization, which doesn't exist yet, so that remains to be fixed.