rework variable sorting, fix typo