Bugfix: store updated variable, corrected sort