         @port = null
         @process = null
         @stopTimeout = null
-        @state = @states.stopped
         @readyCallbacks = []
-
-    states:
-        stopped: 0
-        starting: 1
-        running: 2
 
     start: (readyCallback) =>
         if @stopTimeout?
             clearTimeout @stopTimeout
         @stopTimeout = setTimeout @stop, @serviceManager.config.timeout
 
-        if @state == @states.running
+        if @state() == 'running'
             readyCallback()
             return
-        if @state == @states.starting
-            @readyCallbacks.push readyCallback
+
+        @readyCallbacks.push readyCallback
+        if @state() == 'starting'
             return
 
-        @state = @states.starting
-
-
+        @state 'starting'
         freeport (err, port) =>
             @port = port
             processName = "#{@serviceManager.config.dir}/#{@name}"

                    process.kill(child.PID)
                @process.kill()

module.exports =
    ServiceManager: ServiceManager
    Service: Service

                console.log "#{@name}: stopped, code #{code}, signal #{signal}"
                @port = null
                @process = null
                @state 'stopped'

            # wait until it starts responding to TCP connections before connecting
            tester = =>
