Added code to assign records to datasets