Fixed some errors and improved code for merging datasets (merge options are now configurable in source code).