Fix bug in replaceBindings and add check that nodes match