merge var declarations
directly compare with undefined
merge var declarations
explicitly export public functions

As the whole module is now wrapped in an immediate function, the
majority of the changes are due to adjustments to indentation.