Various fixes provided by Robert Hart, with small changes.
Some of the absolute value tests aren't necessary; we just want
a test for being non-zero. In addition, freeing the result of parseSegs
is a little more delicate.