improve sorting algorithm, updating angular