Bugfix: fix errors when transforming after sorting