Fix PostStartup being fired twice, and PreShutdown never firing. Added test.