refactoring the duplicated tab creation logic