Cleaning up JS here and added legacy support for browsers.