Fix for incorrect sorting