Added marginalization.
Merged Jacco's stuff.