Added event code (with tests)