updated sorting script