                     if url and url not in SCRIPT_URLS
                       script = {type: 'CSS', url, site}
                       SCRIPT_URLS.push url
-                      SCRIPTS.push script
+                      if debug_mode
+                        SCRIPTS.push script
+                      else
+                        getPackageScripts [script], (err, scripts) ->
+                          loadScripts scripts
                   when 'text/javascript'
                     url = attribs.src
                     if url and url not in SCRIPT_URLS
                       script = {type: 'JS', url, site}
                       SCRIPT_URLS.push url
-                      SCRIPTS.push script
+                      if debug_mode
+                        SCRIPTS.push script
+                      else
+                        getPackageScripts [script], (err, scripts) ->
+                          loadScripts scripts
               onend: ->
                 next()
             }
             parser.write body
             parser.end()
-        ), ->
-          done null, SCRIPTS
+
+        if debug_mode
+          async.eachSeries sites, site_iterator, -> done null, SCRIPTS
+        else
+          async.each sites, site_iterator, -> done null, []
+
 
       # create URLs for package/main.js
       getPackageScripts = (scripts, next) ->
-        pkg_scripts = []
-        for {url, type, site} in scripts
+        return next() unless scripts
+        for script in scripts
+          {url, type, site} = script
           continue unless type is 'CSS'
           pkg = PKGtest.exec(url)?[1]
           continue unless pkg
           pkg_JS = "#{pkg}/main.js"
-          if pkg_JS not in pkg_scripts
+          if pkg_JS not in PROCESSED_PACKAGE_SCRIPTS
             scripts.push {site, type: 'JS', url: pkg_JS}
-            pkg_scripts.push pkg_JS
+            PROCESSED_PACKAGE_SCRIPTS.push pkg_JS
 
         next null, scripts
 
       # request CSS and JS scripts
-      loadScripts = (scripts, done) ->
-        async.eachSeries scripts, ((script, next) ->
+      loadScripts = (scripts = [], done) ->
+        return done() unless scripts
+        script_iterator = (script, next) ->
+          return next() unless script
           {url, type, site} = script
           if url.match DOMAINtest
             url = "#{DOMAIN}#{url}"

    debug_mode = true if args[1] is 'debug'
    log 'DEBUG MODE' if debug_mode
    exit "must specify domain" unless DOMAIN

    # connect to DB
    connect (user, db) ->

        SCRIPTS = []
        SCRIPT_URLS = []

        site_iterator = (site, next) =>
          get site, (err, resp, body) ->
            if resp.statusCode < 200 or resp.statusCode > 302 or err
              switch body
