sort array to avoid extraneous arrays