Fixed bug in sorting methods