Reimplementing marginal tree traversal.

Adding unit tests along the way to convince myself it's right.