BUG: fix replace bug when a nested dict was passed