Model for tags, and some refactorings