change some functions to return data.tables