More faithful translation of the F# version.

This one fails for xp0 already. ...progress?!