Fixing incorrect sorting