Refactored tag handling to separate classes.