Fixed bug in caculating the transform

The commit yesterday fixed the issue for some datasets, but screwed up
the transform calculation for others (as discovered today). This edit
has been tested to work on a few different datasets. As always, more
testing is needed...