sort values before assigning