implement this monkeypatch with less code duplication