fixed race
diff --git a/apid.go b/apid.go
index ea4eb8d..596cfe8 100644
--- a/apid.go
+++ b/apid.go
@@ -71,8 +71,8 @@
 		}
 		pie.Plugins = append(pie.Plugins, pluginData)
 	}
-	Events().Emit(SystemEventsSelector, pie)
 	pluginInitFuncs = nil
+	Events().Emit(SystemEventsSelector, pie)
 	log.Debugf("done initializing plugins")
 }
 
diff --git a/events/events_test.go b/events/events_test.go
index 857d7fc..5f8d181 100644
--- a/events/events_test.go
+++ b/events/events_test.go
@@ -290,19 +290,19 @@
 
 				if pie, ok := event.(apid.ShutdownEvent); ok {
 					Expect(pie.Description).Should(Equal("apid is going to shutdown"))
-					close(done)
 				} else {
 					Fail("Received wrong event")
 				}
 			}
 			apid.Events().ListenFunc(apid.ShutdownEventSelector, h)
-			shutdownHandler := func(event apid.Event) {}
-			apid.Events().EmitWithCallback(apid.ShutdownEventSelector, apid.ShutdownEvent{"apid is going to shutdown"}, shutdownHandler)
+			<- apid.Events().Emit(apid.ShutdownEventSelector, apid.ShutdownEvent{"apid is going to shutdown"})
+			close(done)
 		})
 
 		It("handlers registered by plugins should execute before apid shutdown", func(done Done) {
 			pluginNum := 10
 			count := int32(0)
+			countP := &count
 
 			// create and register plugins, listen to shutdown event
 			for i:=0; i<pluginNum; i++ {
@@ -310,7 +310,7 @@
 				h := func(event apid.Event) {
 					if pie, ok := event.(apid.ShutdownEvent); ok {
 						Expect(pie.Description).Should(Equal("apid is going to shutdown"))
-						atomic.AddInt32(&count, 1)
+						atomic.AddInt32(countP, 1)
 					} else {
 						Fail("Received wrong event")
 					}