Oops, noticed a few additional problems. See attached patch.