sorting and testing array for order