Backported deep_dup from rails 4