Modified so that all the functions are in a closure. This way they will not contaminate the global scope, unless explicitly 'exported / returned' or assigned to the global window variable.