Changes to correct sorting