Dependency injection for keys, and event-based messaging
Remove some dead code. And add some tests that were missed.