Added sort, fixed regressions