Fixed deep merge. Added ability to specify a function for elements.