Better fix for #2642

changes made after discussion in #2723