improved tag related code, more tests