Fix bugs in tagging