Adding transformation to the extract code

@yurydelendik, I created a pr on a new branch, hope this doesn't create a problem in generating preview.
I will be closing #3633, please review this pr instead