Credit @codesparkle for #2928, #2934, #2938, #2939