Move event delegation to a different function. Fixes #7