Refactoring and testing events.

Small fixes and cleanup.