sorting + bug fix