Refactors JavaScript to be modularized

Refactors JavaScript into an "instructions" module to avoid polluting
the global scope with properties. Also moves nested functions to the
module scope and establishes public/private scope of module properties
and methods.