gallery sort bug fix