Simplified code and wrapped in IIFE. Minified.