Fix signature generation and sort with TreeMap