There doesn't seem to be a good solution on preserving both the declaration order and sorted variable IDs, so let's just roll a new class that can do both.