       @fail "Failed to start mocha."
 
   waitForMocha: =>
-    ended = @page.evaluate -> mocha.phantomjs?.ended
+    ended = @page.evaluate -> mochaPhantomJS.ended
     if ended then @finish() else setTimeout @waitForMocha, 100
 
   waitForRunMocha: =>
-    started = @page.evaluate -> mocha.phantomjs?.started
-    if started then @runMocha() else setTimeout @waitForRunMocha, 100
+    started = @page.evaluate -> mochaPhantomJS.started
+    if started
+      @runMocha()
+    else
+      setTimeout @waitForRunMocha, 100
 
   runner: (reporter) ->
     try
       mocha.setup reporter: reporter
-      mocha.phantomjs.runner = mocha.run()
-      if mocha.phantomjs.runner
-        mocha.phantomjs.runner.on 'end', ->
-          mocha.phantomjs.failures = @failures
-          mocha.phantomjs.ended = true
+      mochaPhantomJS.runner = mocha.run()
+      if mochaPhantomJS.runner
+        mochaPhantomJS.runner.on 'end', ->
+          mochaPhantomJS.failures = @failures
+          mochaPhantomJS.ended = true
     catch error
       false
 

  customizeRunner: (options) ->
    undefined

  customizeProcessStdout: (options) -> 
    undefined

  customizeConsole: (options) ->

  injectJS: ->
    if @page.evaluate(-> window.mocha?)
      @page.injectJs 'mocha-phantomjs/core_extensions.js'
      @page.evaluate @customizeProcessStdout, @customizeOptions()
      @page.evaluate @customizeConsole, @customizeOptions()
    else
