unit tests and refactoring for tags and posts