Fix for ROOT-6194 and ROOT-6164