Better tab handling in JS