Refactored transform code