Refactored Function file to include all variables an functions in a local scope using IIFE