Solved bug where array was sorted when it shouldn't