Corrected array sort function and added object sort function