Fixed bug with sorting