Update sorting routine