added sort support in loop