Refactoring with some custom event delegation