Optimized the event handler for the theme