Fixed destructive operations bugs with sort