Refactor code for tags