partial conversion to using data.table