Fix longstanding bug around Element names

Also add test cases for the fix.
Element names are
- alphanumeric strings
- may contain '-' and '_'
- start with an uppercase letter