Refactored the code using an IFFE so that there are no variables or function in the global scope.