Fixed a bug in sort that destroyed resultsets too early