Pressing META+T creates a new tab
Pressing META+W closes the current tab (only if it's not the last one)
Pressing from META+1 to META+9 automatically selects the corresponding tab (if it exists)
Simplified code