Added comments. Wrapped the functions to work with Node.js or a browser.