fixed issues with sorting algorithms