Partially fixed and added code for merging datasets.