Fixed _insert_replace_helper; updated $type to $action