better merging with error checking and correct types, fixes #11