Restructure event handling