Code adapted for browsers.