Added boundary check in tab number