changed to use copy(dataset) when input is a data.table