Finished implementation of marginalization