Updated the code to be require- and regular-browser compatible.