Add code for mergin training and test datasets, and some other minor corrections