This transfers permenant and temporary memory back and forth as needed. It saves time, space, and it makes all the other functions easier to use.
I removed the boolperm argument as it is no longer needed