fixed up transform to pass test5d, faster but still need to eliminate some dispatching