Wrapping whole JS script in an anonymous function to avoid global variables