Complete re-factoring

Completely re-factored the code using an IIFE and module pattern
approach