Fixed bug in sorting array.