Use variable to change sorting function