empty tag handling and refactoring