fix various bugs that start from 'undefined' error when destroying a tag.