In terms of avoiding .undefined, I believe that's because the classname is created dynamically and if at any point the id is undefined (recently deleted annotation or recently created annotation before refreshed), we want to make sure that the tags section is removed.

But yes I agree with the rewrite.