refactored transform method