Created tests and fixed sorting algorithm