Working again: simplified code, able to pass handler functions for most merge functions