fixed comments and added sort flag