Added validation and fixed a validation bug with empty or null tags.