Move the sorting variables saving to afterevent