fix sort modifying list by side-effect bug