Bugfixes to transformation code