Refactor TagCheck logic
This cleans refactors the logic in TagCheck to improve readability and code structure.