Rewritten to use event delegation