Update 'extend' function.

Replace the extend function with one that does a genuine deep copy
(copied from JQuery). The extend function no longer overwrites / links
values in the source objects.