         transExt = opts.transExt[i]
         loader.transform StdioTransform.Filter transform, transExt
 
-
-
     # Now we finally pipe the output out of our program. We either pipe it to
     # a file, or STDOUT (if defined)
     if opts.pipe
       outer   = process.stdout
-      loader.on 'end', -> log "KDApp Compiled Successfully!"
+
+      # For pipe, there is nothing we need to end. So when our loader is done,
+      # make sure to add our closure-close, and log success
+      loader.on 'end', ->
+        outer.write "\n})();"
+        log "KDApp Compiled Successfully!"
     else
       outer   = fs.createWriteStream path.join appPath, opts.file
-      outer.on 'finish', -> log "KDApp Compiled Successfully!"
+
+      # When our loader is done, close our closure and end the file stream
+      loader.on 'end', -> outer.end "\n})();"
+      # We wait till the file stream ends fully to ensure we don't prematurely
+      # call success if an error occurs.. it just looks bad when you do that.
+      outer.on 'finish', ->
+        log "KDApp Compiled Successfully!"
 
     loader.on 'error', (err) ->
       log "Error Compiling KDApp: #{err.message}"

# calculates options and ensures a manifest loads.
exec = (argv, log=console.error) ->
  program = require 'commander'
  program.version '@@version'

  # Compile command and opts
  compileCmd  = program.command 'compile'

  compileCmd.description 'Compile a KDApp'
  compileCmd.option '-c, --coffee', 'CoffeeScript support'
  compileCmd.option '-n, --commonjs', 'Commonjs support'
  compileCmd.option '-b, --bare', 'For languages that support it, no closure'
  compileCmd.option '-t, --transform <bin>', 'Add a Stream Transform Binary'
  compileCmd.option '-e, --trans-ext <ext>', 'A file extension filter '+
    'for the previous transform'
