Removed requirement for plyr, and used data.table features instead.