countTabs function fix from branch