When checking if a tag exists there is no "normalization" of the searched tag. Although the tags are trimmed in the function addTag, the searched tag in tagExist is not trimmed. This may cause a problem when adding new tags. I had this problem until I solved it.