Code from http://www.cis.upenn.edu/~xtag/spinal/