Add tests for some bugs and new option

Fix some bugs due to expansion not being applied correctly at the
toplevel.

Also Add an option to allow remapping inconsistent keys to a subkey by
adding a second parameter to the expand() method.
Refactor to use mergeTwoValues function in deferenceDots