(cherry picked from commits c7896f31026d6bdee189226680705dd7965b2039 and 40c78cac4c430a97386b44b994ec85fbaeda8821)