Fixed big bug in sorting method.