Fix bug where casting of merged hash could modify original one