added sort optional

sort added as variable to function