Fix possible double-registration and element selector. Fixes #5
Merge with upstream