Changes to make the JS code relocatable (phase 1)