Re-factored the example code

You can now load script.html in your browser and see it work using the
console.