Fixed memory leaks
Introduced Sorting