Refactored tag parsing in tsd_get() and helper functions