added better tab logic