Refactored code for getting tags.