Fixed #42.

See comments on the issue for details of the fix.