Factored stuff out into a Tag class.

(... to prepare for unittests ...)