Attempted global sort function in place though not working