improve code to sort signatures
-avoid duplicate checks
-use a better check if something is a unknown reference, which does not need any
string operations anymore and does not get confused if someone creates a key
where the name starts with '['