Avoid returning duplicate tags, fixes #817