refacted some code in tags.js