Improved tag logic