Added sortArray function