Replace 'global' by 'window' in JS code.
Comment old unused parts.