Refactoring open tab handler (with events)