added code to correctly select tab