Event listener

I rebased with respect to master. Then some reformatting, fixed unit tests.