added resequencing code