Fixing faulty sorting