finished transformation function
The original code seems to work actually. Reverting back with a few minor changes
fixing old dri bug