streamlined and fixed transformation code