Re-wrote to use data.table