rewrote array to sort properly