Move event handler to attachEvents()