Simplify logic and fix count of pinned tabs